using System;
using System.Collections.Generic;
using System.Text;

namespace Weight.Base.Utility
{
    public class  GetIdHelper
    {
       public string  GetGuid()
        {
            System.Guid guid = new Guid();
             guid = Guid.NewGuid();
             return guid.ToString();
        }

             /// <summary>  
         /// 根据GUID获取16位的唯一字符串  
         /// </summary>  
         /// <param name=\"guid\"></param>  
         /// <returns></returns>  
         public  string GuidTo16String()
         {
             long i = 1;
             foreach (byte b in Guid.NewGuid().ToByteArray())
                 i *= ((int) b + 1);
             return string.Format("{0:x}", i - DateTime.Now.Ticks);
         }
         /// <summary>  
         /// 根据GUID获取19位的唯一数字序列  
         /// </summary>  
         /// <returns></returns>  
         public  long GuidToLongID()
         {
             byte[] buffer = Guid.NewGuid().ToByteArray();
             return BitConverter.ToInt64(buffer, 0);
         } 
        
        /// <summary>
        /// 根据时间获取Id
        /// </summary>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public string GetDateTimeId(string prefix)
        {
            return prefix + DateTime.Now.ToString("yyyyMMddHHmmss");
        }

        /// <summary>
        /// 根据时间获取Id
        /// </summary>
        /// <param name="prefix">前缀</param>
        /// <returns></returns>
        public string GetDateTimeAndRandId(string prefix)
        {
            string tmp = Convert.ToString( new Random((int)DateTime.Now.Ticks).Next()).PadLeft(8,'0');
            tmp = tmp.Substring(3,4);
            return prefix + DateTime.Now.ToString("yyyyMMddHHmmss")+ tmp;
        }
    }
}


